<template>
  <div>
    <div class="title">
      <van-icon name="arrow-left" @click="back" size="28" />
      <p class="title-m">所在城市</p>
      <p class="right" @click="success">完成</p>
    </div>
    <van-index-bar :sticky-offset-top="Number(116)">
      <template v-for="(value, k, i) in cityObj">
        <van-index-anchor :key="i + 525" :index="k" />
        <van-cell
          v-for="item in value"
          :key="item.cityId"
          :title="item.name"
          @click="getCity(item.name, item.cityId)"
          :style="{ color: flag == item.cityId ? 'red' : 'black' }"
        />
      </template>
    </van-index-bar>
  </div>
</template>

<script>
import { mapState, mapActions } from "vuex";
export default {
  data() {
    return {
      flag: false,
      place: "",
    };
  },
  computed: {
    ...mapState("li", ["cityObj"]),
  },
  methods: {
    ...mapActions("li", ["upProfile"]),

    //取消
    back() {
      this.$router.back();
    },
    //获取城市
    getCity(city, id) {
      this.place = city;
      this.flag = id;
    },
    //成功
    success() {
      this.upProfile({ place: this.place });
    },
  },
};
</script>

<style lang="scss" scoped>
.title {
  display: flex;
  align-items: center;
  position: sticky;
  top: 0;
  z-index: 5;
  background-color: white;
  .title-m {
    flex: 1;
    text-align: center;
    margin: 24px 0 40px 0;
    font-size: 40px;
    font-weight: bold;
  }
  .right {
    font-size: 28px;
    margin-right: 26px;
  }
}
.van-index-bar__index {
  font-size: px;
}
.van-cell__title {
  font-size: 28px;
}
</style>